package com.boesch.electroOffice.business.businessObjectImpl;

import java.io.Serializable;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.boesch.electroOffice.business.businessObject.CustomerBusinessObject;
import com.boesch.electroOffice.business.common.BusinessException;
import com.boesch.electroOffice.dataaccess.common.IllegalDataAccessException;
import com.boesch.electroOffice.dataaccess.dao.messerli.CustomerDao;
import com.boesch.electroOffice.model.messerli.Customer;
import com.liferay.portal.model.User;

/**
 * This class handles all the business logic 
 * for package com.boesch.electroOffice.application.customer
 * 
 * If there is no business logic, the class just calls the appropriate class
 * from package com.boesch.electroOffice.dataaccess to read the data from database
 * 
 * 
 * @author Ralph Koster
 *
 */
@Service
public class CustomerBusinessObjectImpl implements CustomerBusinessObject, Serializable {
	
	private static final long serialVersionUID = 6303638590999558920L;
	
	@Autowired
	private CustomerDao customerDao;	
	
	public Customer readCustomerByCustomerId(int customerId)
			throws IllegalDataAccessException, BusinessException {
		return customerDao.readCustomerByCustomerId(customerId);
	}
	
	public Customer readCustomerByCustomerEmailAddress(String emailAddress)
			throws IllegalDataAccessException, BusinessException {
		return customerDao.readCustomerByEmailAddress(emailAddress);
	}
	
	public List<Customer> readCustomersByNameAndFirstname(String firstname, String lastname)
			throws IllegalDataAccessException, BusinessException {
		return customerDao.readCustomersByName(firstname, lastname);
	}
	
	public List<Customer> readAllCustomers()
			throws IllegalDataAccessException, BusinessException {
		return customerDao.readAllCustomers();
	}
	
	public List<String> readAllSalutations()
			throws IllegalDataAccessException, BusinessException {
		return customerDao.readAllSalutations();
	}
	
	public String saveCustomer(Customer customer, User currentUser)
			throws IllegalDataAccessException, BusinessException {
		return customerDao.saveCustomerOnDatabase(customer, currentUser);
	}
	
	public String updateCustomer(Customer customer, User currentUser)
			throws IllegalDataAccessException, BusinessException {
		return customerDao.updateCustomerOnDatabase(customer, currentUser);
	}	
}
